package cn.jbit.servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.jbit.news.dao.impl.NewsDaoImpl;
import org.jbit.news.entity.News;

@SuppressWarnings("serial")
public class NewsChange extends HttpServlet{

	@Override
	protected void service(HttpServletRequest request, HttpServletResponse resp)
			throws ServletException, IOException {
		request.setCharacterEncoding("UTF-8");
		resp.setCharacterEncoding("UTF-8");
		resp.setContentType("text/html;charset=UTF-8");
		int ntid=Integer.valueOf(request.getParameter("ntid"));
    	String ntitle=request.getParameter("ntitle");
    	String nauthor=request.getParameter("nauthor");
    	String nsummary=request.getParameter("nsummary");
    	String ncontent=request.getParameter("ncontent");
    	HttpSession session=request.getSession();
    	News news1=(News)session.getAttribute("news");
    	session.removeAttribute("news");
    	News news=new News();
    	news.setNtid(ntid);
    	news.setNtitle(ntitle);
    	news.setNauthor(nauthor);
    	news.setNsummary(nsummary);
    	news.setNcontent(ncontent);
    	NewsDaoImpl nd=new NewsDaoImpl();
    	int result=nd.update(news,news1.getNid());
    	PrintWriter out=resp.getWriter();
    	if(result>0){
    		resp.sendRedirect("newspages/admin.jsp");
    	}else{
    		out.println("对不起");
    		out.close();
    	}
	}

	@Override
	public void destroy() {
		// TODO Auto-generated method stub
		super.destroy();
	}

	@Override
	public void init() throws ServletException {
		// TODO Auto-generated method stub
		super.init();
	}
	
}
